// FFEncodeFilter.cpp : Defines the initialization routines for the DLL.
//

#include "stdafx.h"
#include "FFEncode.h"
#include "FFEncodeFilter.h"
#include <InitGuid.h>
#include "mqguid.h"





#define countof(array) (sizeof(array)/sizeof(array[0]))

template <class T>
static CUnknown* WINAPI CreateInstance(LPUNKNOWN lpunk, HRESULT* phr)
{
	*phr = S_OK;
	CUnknown* punk = new T(lpunk, phr);
	if(punk == NULL) *phr = E_OUTOFMEMORY;
	return punk;
}


#ifdef _DEBUG
#define new DEBUG_NEW
#endif



const AMOVIESETUP_MEDIATYPE sudPinTypesInV[] =
{
	{&MEDIATYPE_Video, &MEDIASUBTYPE_NULL}
};

const AMOVIESETUP_MEDIATYPE sudPinTypesInA[] =
{
	{&MEDIATYPE_Audio, &MEDIASUBTYPE_NULL}
};

const AMOVIESETUP_PIN sudpPins[] =
{
	{L"Video Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesInV), sudPinTypesInV},
	{L"Audio Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesInA), sudPinTypesInA}
};

const AMOVIESETUP_FILTER sudFilter[] =
{
	{&CLSID_XFFENCODER, MY_FILTER_NAME, MERIT_DO_NOT_USE, countof(sudpPins), sudpPins}
};

CFactoryTemplate g_Templates[] =
{
	{sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CFFEncodeFilter>, NULL, &sudFilter[0]}
};

int g_cTemplates = countof(g_Templates);

STDAPI DllRegisterServer()
{
	HRESULT hr ;
	hr =  AMovieDllRegisterServer2(TRUE);
	return hr;
}

STDAPI DllUnregisterServer()
{
	return AMovieDllRegisterServer2(FALSE);
}



extern "C" BOOL WINAPI DllEntryPoint(HINSTANCE, ULONG, LPVOID);

// CFFEncodeFilterApp
BEGIN_MESSAGE_MAP(CFFEncodeFilterApp, CWinApp)
END_MESSAGE_MAP()


// CFFEncodeFilterApp construction

CFFEncodeFilterApp::CFFEncodeFilterApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}


// The one and only CFFEncodeFilterApp object

CFFEncodeFilterApp theApp;


// CFFEncodeFilterApp initialization

BOOL CFFEncodeFilterApp::InitInstance()
{

	if(! __super::InitInstance())
		return FALSE;

	DllEntryPoint(AfxGetInstanceHandle(), DLL_PROCESS_ATTACH, 0);

	return TRUE;
}

BOOL CFFEncodeFilterApp::ExitInstance()
{
	DllEntryPoint(AfxGetInstanceHandle(), DLL_PROCESS_DETACH, 0);

	return __super::ExitInstance();
}